package com.tzbank.wisdom.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import com.alibaba.fastjson.JSON;
import com.tzbank.esb.util.EsbConsumerUtil;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultCode;
import com.tzbank.utils.ResultUtil;
import com.tzbank.wisdom.service.LoginTypeService;
import com.tzbank.wisdom.utils.RequestMap;
import com.tzbank.wisdom.utils.TransCodeEnum;

import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
public class LoginTypeServiceImpl implements LoginTypeService {

	@Override
	public Map<String, Object> bindDevice(@RequestBody Map<String, Object> paramMap) {
		log.info("个人登录方式切换绑定设备信息 请求参数:" + JSON.toJSONString(paramMap));
		
		Map<String, Object> inputMap = new HashMap<>();
		Map<String, Object> reqSysHead = new HashMap<>();
		
		String clientSeqNo = paramMap.get("clientSeqNo").toString();
		String deviceId = paramMap.get("deviceId").toString();
		
		Map<String,Object> userMap =RequestMap.getInputUserInfo(clientSeqNo);
		if (userMap.get("clientNo") == null) {
			return userMap;
		}
		
		reqSysHead = RequestMap.getReqSysHead(TransCodeEnum.DEVICE_BIND.getServiceCode(), TransCodeEnum.DEVICE_BIND.getServiceSence(), "0110");
		inputMap = RequestMap.getInputMap(paramMap);
		
		inputMap.putAll(userMap);
		inputMap.put("sysHead", reqSysHead);
		inputMap.put("termNo", deviceId);
		
		log.info("个人登录方式切换绑定设备信息 请求开始...");
		Map<String, Object> result = EsbConsumerUtil.clientRequest(inputMap);
		log.info("个人登录方式切换绑定设备信息 请求结束 响应结果：{}", result);
		if (CodeUtil.CODE_200.getCode().equals(result.get("code"))) {
			return ResultUtil.resultMap("设备绑定成功", ResultCode.RESULT_CODE_SUCCESS.code(), null);
		}
		return ResultUtil.resultMap(result.get("msg").toString(), ResultCode.RESUTL_CODE_FAILURE.code(), result.get("data"));
	}

}
